home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / ae / code / acp3.00 / restrict.h < prev    next >
Encoding:
Text File  |  1996-02-18  |  1.3 KB  |  69 lines

  1. void Restrict(char *str)
  2. {
  3.    BPTR  FLock;
  4.    int bad=TRUE;
  5.    struct FileInfoBlock *FBlock;
  6.    if((FLock=Lock(str,ACCESS_READ))!=0)
  7.    {
  8.      if((FBlock=AllocMem((long)sizeof(struct FileInfoBlock),MEMF_CHIP)) == NULL)
  9.      { 
  10.        bad=TRUE; 
  11.      }
  12.      else 
  13.      { 
  14.        if((Examine(FLock,FBlock))==0)
  15.        {  
  16.           
  17.          bad=TRUE;  
  18.        }
  19.        else
  20.        { 
  21.      
  22.            bad=FALSE;  
  23.        }
  24.        FreeMem(FBlock,sizeof(struct FileInfoBlock));
  25.     }
  26.     UnLock(FLock);
  27. if(!bad) SetComment(str,"Restricted");
  28.    }
  29.     
  30. }
  31. void Backup(char *str,int cycle)
  32. {
  33.   BPTR fi,fo;
  34.   char ch[10];
  35.   int num;
  36.   char im1[200];
  37.   char im2[200];
  38.   num=cycle;
  39.   
  40.   if(TLock(str))
  41.   {
  42.      while(cycle)
  43.      {
  44.        sprintf(im1,"%s{%d}",str,cycle);
  45.        if(TLock(im1))
  46.        {
  47.           if(cycle==num)
  48.           {  
  49.             DeleteFile(im1); cycle -=1; continue; 
  50.           }
  51.           sprintf(im2,"%s{%d}",str,cycle+1);
  52.           Rename(im1,im2);
  53.           Restrict(im2);
  54.        }
  55.        cycle--;
  56.      }
  57.      sprintf(im1,"%s{1}",str);
  58.      Rename(str,im1);
  59.      fi=Open(im1,MODE_OLDFILE);
  60.      fo=Open(str,MODE_NEWFILE);
  61.      while(FRead(fi,(APTR)&ch,sizeof(char),1)!=NULL)
  62.        Write(fo,(APTR)&ch,sizeof(char));
  63.      Close(fo);
  64.      Close(fi);
  65.      Restrict(im1);
  66.      Restrict(str);
  67.   }
  68. }
  69.